/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __AX_UTILS_H__
#define __AX_UTILS_H__
#include <mach/debug.h>

typedef int (*os_wait_cond_func_t)(const void *param);
typedef struct os_wait {
	void *wait;
} os_wait_t;

int axvu_wait_init(os_wait_t *wait);
int axvu_wait_interruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param);
int axvu_wait_uninterruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param);
int axvu_wait_timeout_interruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param, unsigned long ms);
int axvu_wait_timeout_uninterruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param, unsigned long ms);
void axvu_wakeup(os_wait_t *wait);
void axvu_wait_destroy(os_wait_t *wait);

typedef struct os_mutex {
	void *mutex;
} os_mutex_t;
int axvu_mutex_init(os_mutex_t *mutex);
int axvu_mutex_lock(os_mutex_t *mutex);
int axvu_mutex_lock_interruptible(os_mutex_t *mutex);
int axvu_mutex_trylock(os_mutex_t *mutex);
void axvu_mutex_unlock(os_mutex_t *mutex);
void axvu_mutex_destroy(os_mutex_t *mutex);
unsigned int axvu_jiffies_to_msecs(const unsigned long long j);



#ifndef os_readl
#define os_readl(reg)			readl((void __iomem *)(reg))
#endif
#ifndef os_writel
#define os_writel(val, reg)		writel((val), (void __iomem *)(reg))
#endif



#define ax_err(n, x, arg...) \
	do { \
		if (n == 1) \
			PRT_ERR("[VU_ERR]"x, ##arg); \
		if (n == 2) \
			PRT_INFO("[VU_INFO]"x, ##arg); \
	} while (0)


#define os_gfp_kernel				0
#define os_gfp_atomic				1

void *axvu_kzalloc(unsigned long size, unsigned int os_gfp_flag);
void *axvu_kmalloc(unsigned long size, unsigned int os_gfp_flag);
void axvu_kfree(const void *addr);
void axvu_getjiffies(unsigned long long *pjiffies);
void axvu_udelay(unsigned int usecs);
void axvu_mdelay(unsigned int msecs);
unsigned long axvu_msecs_to_jiffies(const unsigned int m);
#endif
